package com.buobao.reflect.demo;

import com.buobao.reflect.demo.entity.Employee;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;

/**
 * 通过构造反射创建对象示例
 */
public class ConstructorSample {
    public static void main(String[] args) {
        try {
            Class employClass = Class.forName("com.buobao.reflect.demo.entity.Employee");
            Constructor constructor = employClass.getConstructor(new Class[]{int.class,String.class,float.class,String.class, Date.class});
            Employee employee = (Employee) constructor.newInstance(new Object[]{2001,"ZhangSan",8000.0f,"Designer",new Date()});
            System.out.println(employee);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
